package cn.tedu.shoot;

import java.awt.image.BufferedImage;

//英雄机
public class Hero extends FlyingObject{

    private int life;   //命
    private int fire;   //火力值

    public Hero(){
        super(97,139,140,400);
        life = 3;
        fire = 0;
    }

    public void step(){
        //暂时搁置
    }

    int index =0;
    public BufferedImage getImage(){ //每10毫秒走一次
        return Images.hero[index++%Images.hero.length]; //heros[0]和heros[1]来回切换
           /* 执行过程:
                                 index=0
              10M  返回heros[0]  index=1
              20M  返回heros[1]  index=2
              30M  返回heros[0]  index=3
              40M  返回heros[1]  index=4
              50M  返回heros[0]  index=5
            */
    }

    //英雄机发射子弹(生成子弹对象)
    public Bullet[] shoot(){
        int xStep = this.width/4; //1/4英雄机的宽
        int yStep = 20; //固定的20
        if(fire>0){ //双倍
            Bullet[] bs = new Bullet[2]; //2发子弹
            bs[0] = new Bullet(this.x+1*xStep,this.y-yStep); //x:英雄机的x+1/4英雄机的宽  y:英雄机的y-固定的20
            bs[1] = new Bullet(this.x+3*xStep,this.y-yStep); //x:英雄机的x+3/4英雄机的宽  y:英雄机的y-固定的20
            fire-=2; //发射一次双倍火力，则火力值减2
            return bs;
        }else{ //单倍
            Bullet[] bs = new Bullet[1]; //1发子弹
            bs[0] = new Bullet(this.x+2*xStep,this.y-yStep); //x:英雄机的x+2/4英雄机的宽  y:英雄机的y-固定的20
            return bs;
        }
    }

    public void moveTo(int x,int y){
        this.x = x-this.width/2;
        this.y = y-this.height/2;
    }

    public void addLife(){
        life ++;
    }

    public void addFire(){
        fire += 40;
    }

    public void clearFire(){
        fire = 0;
    }

    public int getLife(){
        return life;
    }

    public void subtractLife(){
        life--;
    }



}
